package July;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Day0724 {

    //参数解析
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();

        char[] ch = str.toCharArray();
        List<String> list = new ArrayList<>();

        boolean f = false;
        String temp = "";

        for (int i = 0; i < ch.length; i++) {
            if (ch[i] == '\"' && !f){
                f = true;
                continue;
            }

            if (ch[i] == '\"' && f){
                f = false;
                continue;
            }

            if (ch[i] == ' ' && f){
                temp += ch[i];
                continue;
            }

            if(ch[i] == ' '){
                list.add(temp);
                temp ="";
                continue;
            }
            temp += ch[i];
        }
        list.add(temp);

        System.out.println(list.size());

        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }


    //跳石板

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int res = dp(n,m);
        System.out.println(res);
    }

    private static int dp(int n, int m) {

        int[] dp =new int[m+1];

        for (int i = n; i <= m ; i++) {
            dp[i] = -1;
        }

        int st = 1;
        dp[n] = 0;

        while (dp[m] == -1){
            int max = Integer.MAX_VALUE;

            for (int i = n; i <= m ; i++) {
                if (dp[i] > max){
                    max = dp[i];
                }
                if (dp[i] < st-1){
                    continue;
                } else if (dp[i] == st-1) {
                    for (int j = 2; j <= Math.sqrt(i) ; ++j) {
                        if ( i % j == 0){
                            if (i + j <= m && dp[i+j] == -1)
                                dp[i+j] = st;
                            if (i+i/j <= m && dp[i+i/j] == -1)
                                dp[i+i/j] = st;
                        }
                    }
                }else {
                    continue;
                }
            }
            if (st - max >1)
                break;
            st++;
        }
        return dp[m];
    }
}
